package lambda;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class LambdaDemo1 {
    public static void main(String[] args) {
        //为字符串定义一个比较规则(字符从多到小),匿名内部类写法
        Comparator<String> c1=new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o2.length()-o1.length();
            }
        };
        //lambda表达式写法
        Comparator<String> c2=(String o1,String o2)->{
            return o2.length()-o1.length();
        };
        //lambda表达式中参数类型可以 忽略不写
        Comparator<String> c3=(o1,o2)->{
            return o2.length()-o1.length();
        };
        Comparator<String> c4=(o1,o2)->o2.length()-o1.length();

        List<String> list=new ArrayList<>();
        list.add("王克晶");
        list.add("范传奇");
        list.add("王伟超");
        Collections.sort(list,((o1, o2) -> o2.length()-o1.length()));
        System.out.println(list);
    }
}
